package middlerware

import (
	sentinel "github.com/alibaba/sentinel-golang/api"
	"github.com/alibaba/sentinel-golang/core/base"
	"github.com/gin-gonic/gin"
	"net/http"
)

func QPS() gin.HandlerFunc {
	return func(c *gin.Context) {
		_, b := sentinel.Entry("some-test", sentinel.WithTrafficType(base.Inbound))
		if b != nil {
			c.JSON(http.StatusBadRequest, gin.H{
				"code": -1,
				"msg":  "访问的太频繁",
				"data": nil,
			})
			c.Abort()
			return
		}
	}
}
